﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Kugar.UI.WinForm
{
    public class TotalColumnRow_Max : TotalColumnRowBase
    {
        protected override object GetColumnTotalValue(DataGridViewColumn column)
        {
            if (!labelMappingCache.ContainsKey(column))
            {
                return null;
            }

            var rowCount = GridSource.Rows.Count;

            if (rowCount <= 0)
            {
                return null;
            }

            var colIndex = column.Index;

            var result = (IComparable)GridSource.Rows[0].Cells[colIndex].Value;

            for (int i = 0; i < rowCount; i++)
            {
                var value = (IComparable)GridSource.Rows[i].Cells[colIndex].Value;

                if (value == null)
                {
                    continue;
                }

                if (result==null)
                {
                    result = value;
                }
                else
                {
                    if(result.CompareTo(value)<0)
                    {
                        result = value;
                    }
                }
            }

            return result;
        }
    }
}
